import {request,setDictTextInfo} from '../utils/util';
const defaultSettings = require('../config/defaultSettings')
const url = {
  dictInfo:defaultSettings.appServer+'/AppExcludeController/getDictInfo',
}

async function getDictInfo(dictCode,params){
  if(!params){
    params=""
  }
  return request({url:url.dictInfo,method:'get',data:{dictCode:dictCode,dictParam:params}});
  
}

async function initDict(dictCodes,params){
  if(!params){
    params=''
  }
  if(!dictCodes){
      return
  }
  await getDictInfo(dictCodes,params).then(res=>{
    if(res.success){
      for(let d in res.result){
        getApp().globalData.dictInfo[d] = res.result[d]
      }
      // setTimeout(() => {
      //   setDictTextInfo(dictCodes)
      // }, 10);

      setDictTextInfo(dictCodes)
    }
  })
}

module.exports = {
  getDictInfo,
  initDict
}